package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/7/31 10:17
 * @apiNote
 */

public class Test00504ConvertToBase7 {
    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }
        boolean negative = num < 0;
        num = Math.abs(num);
        StringBuilder sb = new StringBuilder();
        while(num > 0){
            sb.append(num%7);
            num/=7;
        }
        if(negative){
            sb.append('-');
        }
        return sb.reverse().toString();
    }
}
